<template>
  <div class="menu-left">
    <el-menu
      default-active="0 + ''"
      class="el-menu-vertical-demo"
      background-color="#5271FF"
      text-color="#fff"
      active-text-color="#ffd04b"
      width="250px"
      unique-opened
    >
      <el-menu-item index="0" style="text-align: center">
        <img
          src="../assets/logo_trans.png"
          style="width: 100px; height: 50px"
        />
      </el-menu-item>
      <el-menu-item index="9" style="text-align: center" @click="handlerRoute('/dashboards')">
        <!-- 一级菜单标题 -->
        <template slot="title">
          <div style="margin: 0px auto">
            <i class="el-icon-s-marketing"></i>
            <span>数据看板</span>
          </div>
        </template>
      </el-menu-item>
      <!-- 一级菜单 -->
      <el-submenu
        :index="item.menuId + ''"
        v-for="item in menulist"
        :key="item.menuId"
      >
        <!-- 一级菜单标题 -->
        <template slot="title">
          <div style="margin: 0px auto">
            <i :class="item.icon"></i>
            <span>{{ item.menuName }}</span>
          </div>
        </template>
        <!-- 一级菜单对应的二级菜单 -->
        <el-menu-item
          :index="item.menuId + '-' + subitem.menuId"
          v-for="subitem of item.children"
          :key="subitem.menuId"
          @click="handlerRoute(subitem.href)"
        >
          {{ subitem.menuName }}
        </el-menu-item>
      </el-submenu>
    </el-menu>
  </div>
</template>

<script>
export default {
  data() {
    return {
      menulist: [],
    };
  },
  methods: {
    handlerRoute(url) {
      console.log(url);
      this.$router.push(url);
    },
  },
  mounted() {
    this.menulist = JSON.parse(sessionStorage.getItem("menuList"));
  },
};
</script>
<style>
.menu-left .el-menu-item {
  text-align: right;
}
</style>
